package com.cat.service;

import com.cat.common.BooleanState;
import com.cat.common.ImgState;
import com.cat.mybatis.dao.ImgSourceDao;
import com.cat.mybatis.domain.ImgDisplayDO;
import com.cat.mybatis.domain.ImgSourceDO;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 展示逻辑
 *
 * @author xiemh
 * @date 2018/12/18 21:23
 * @since v1.0.0
 */
@Service
public class DisplayService {
    @Resource
    ImgSourceDao imgSourceDao;

    public List<ImgDisplayDO> queryPage() {
        return null;
        //TODO
    }

    /**
     * 功能: 把source的可用链接搬运到display
     *
     * @author: xiemh
     * @date: 2018/12/20 14:16
     * @since： v1.0
     * @param: []
     * @return: void
     */
    public void transferDisplay() {
        //1.查询imgSource状态为已下载的列表
        //TODO 分批
        List<ImgSourceDO> sourceList = imgSourceDao.selectByState(ImgState.Downloaded.getCode());

        //2.转换成display
        List<ImgDisplayDO> displayList = Lists.newArrayList();
        for (ImgSourceDO source : sourceList) {
            ImgDisplayDO display = new ImgDisplayDO();
            display.setImgId(source.getImgId());
            display.setSmallPath(source.getSmallPath());
            display.setPath(source.getPath());
            display.setDisplayState(BooleanState.YES.getCode());
            display.setTypeId(0);
            displayList.add(display);
        }

        //3.保存display

    }
}

